//
//  AppDelegate.swift
//  MOKOAnnounce
//
//  Created by _SS on 2017/7/7.
//  Copyright © 2017年 cc.moko. All rights reserved.
//

import UIKit
import MJExtension


@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

        self.window = UIWindow.init(frame: UIScreen.main.bounds)
        self.window?.backgroundColor = UIColor.white
        
//        let loginVc = MKLoginViewController()
//        let tabBarViewController:MKTabBarViewController = MKTabBarViewController()
//        self.window?.rootViewController = loginVc
        MKLunchManager.shared.lunch(userType: MKUserType.Businessmen)
        self.window?.makeKeyAndVisible()
        return true
    }

    func applicationWillResignActive(_ application: UIApplication) {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
    }

    func applicationDidEnterBackground(_ application: UIApplication) {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }

    func applicationWillEnterForeground(_ application: UIApplication) {
        // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
    }

    func applicationDidBecomeActive(_ application: UIApplication) {
        version()
    }
    // 版本管理
    func version() -> Void {
        UserDefaults.standard.removeObject(forKey: useridStr as String)
        SessionRequestSender().send(VersionRequest(version:(Bundle.main.infoDictionary!["CFBundleShortVersionString"] as! NSString) as String,method: .get), analysis:
            { VersionResponde in
                let model:MKVersionModel = MKVersionModel.mj_object(withKeyValues: VersionResponde?.data)
                UserDefaults.standard.set(model.apiurl, forKey:apiurlStr as String)
                // post 登陆
                SessionRequestPostSender().send(LoginRequest(apiURL: "/auth", mobile:"13718164578",passwd:"123456", method: .post), analysis: { LoginResponde in
                    let model:MKResponseModel = MKResponseModel.mj_object(withKeyValues: LoginResponde?.data)
                    if (model.resultcode?.isEqual("ok"))!{
                        let userModle:MKLoginUserModel = MKLoginUserModel.mj_object(withKeyValues: model.info)
                        UserDefaults.standard.set(userModle.userid, forKey:useridStr as String)
                        
                        self.initData()

                        
                        // get  获取认证信息
                        SessionRequestPostSender().send(GetRequest(apiURL: "/certificate/bizStatus", method: .get), analysis: {GetResponde in
                            let model:MKResponseModel = MKResponseModel.mj_object(withKeyValues: LoginResponde?.data)
                            if (model.resultcode?.isEqual("ok"))!{
                                
                            }else{
                                // 成功的其他情况的展示
                            }
                        })
                        
                    }else{
                        // 成功的其他情况的展示
                    }
                })
                
        })
        
    }

    func initData() -> Void {
        MKNetWorkTool.getRequest(url: "/certificate/bizStatus", params: nil, success: { (response, responseObject) in
            let model:MKResponseModel = MKResponseModel.mj_object(withKeyValues: responseObject)
            print("审核结果 --- \(model.resultcode!)")
            print("info----\(model.info!)")
        }) { (response, error) in
            
        }
    }

    func applicationWillTerminate(_ application: UIApplication) {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }


}

